import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:xinxuan/http/http_util_service.dart';
import 'package:xinxuan/router/app_routers.dart';
import 'package:xinxuan/vo/address_list_vo.dart';
import 'package:xinxuan/vo/common_vo/common_address_item_vo.dart';
import 'package:xinxuan/vo/submit_order_vo.dart';

class StoreConfirmOrderPageController extends GetxController {
  
  /// 地址列表
  var addressItem = CommonAddressItem(id: 0).obs;

  @override
  void onReady() {
    getAddressList();
    super.onReady();
  }

  /// 获取收货地址列表
  getAddressList() async {
    AddressListVo addressListVo = await HttpUtilService.getAddressList();
    if (addressListVo.data!.length > 0) {
      addressItem.value = addressListVo.data![0];
      update();
    }
  }

  /// 提价订单
  submitOrder(int productId, int skuId, int quantity) async {
    if (addressItem.value.id! <= 0) {
      EasyLoading.showToast('请选择收货地址');
      return;
    }
    SubmitOrderVo sbumitOrderVo = await HttpUtilService.submitStoreOrder(productId: productId, skuId: skuId, quantity: quantity, addressId: addressItem.value.id!);
    Get.offAndToNamed(
      '${AppRouters.COMMON_PAGE}${AppRouters.GOOD_DETAIL_PAGE}${AppRouters.STORE_CONFIRM_ORDER_PAGE}${AppRouters.STORE_ORDER_PAY_PAGE}',
      arguments: {
        'orderId': sbumitOrderVo.data!.id,
        'isDetail': true
      }
    );
  }


}